package com.oscar.ehome.presenter;

import com.oscar.ehome.bean.pagebean.ClassRoomBean;
import com.oscar.ehome.bean.pagebean.ClassRoomPrombleBean;
import com.oscar.ehome.model.HttpModel;
import com.oscar.ehome.model.HttpModelImple;
import com.oscar.ehome.model.OnHttpListener;
import com.oscar.ehome.view.pageview.view.ClassRoomView;

/**
 * Created by juxing
 * author: MengWanhe
 * date: On 2017/9/15
 */

public class ClassRoomPresenter extends BasePresenter {

    ClassRoomView view;
    HttpModel httpModel;

    public ClassRoomPresenter(ClassRoomView view) {
        this.view = view;
        httpModel = new HttpModelImple();
    }

    /**
     * 获取长知识列表
     */
    public void getKnowList(String token, String pageNo, String pageSize) {
        httpModel.getKnowList(token, pageNo, pageSize, new OnHttpListener<ClassRoomBean>() {
            @Override
            public void onSuccess(ClassRoomBean obj) {
                if (view != null)
                    view.knowledgeList(obj);
            }

            @Override
            public void onError(String msg) {
                if (view != null)
                    view.erry(msg);
            }

            @Override
            public void onFailure() {
                if (view != null)
                    view.erroy();
            }
        });
    }

    /**
     * 获取长知识问答列表
     */
    public void getPrombleList(String token, String knowledgeId) {
        httpModel.getPrombleList(token, knowledgeId, new OnHttpListener<ClassRoomPrombleBean>() {
            @Override
            public void onSuccess(ClassRoomPrombleBean obj) {
                if (view != null)
                    view.problemList(obj);
            }

            @Override
            public void onError(String msg) {
                if (view != null)
                    view.erry(msg);
            }

            @Override
            public void onFailure() {
                if (view != null)
                    view.erroy();
            }
        });
    }

    /**
     * 发送问题
     */
    public void sendPromble(String token, String knowledgeId, String remarks) {
        httpModel.sendPromble(token, knowledgeId, remarks, new OnHttpListener<String>() {
            @Override
            public void onSuccess(String obj) {
                if (view != null)
                    view.sendpromble(obj);
            }

            @Override
            public void onError(String msg) {
                if (view != null)
                    view.erry(msg);
            }

            @Override
            public void onFailure() {
                if (view != null)
                    view.erroy();
            }
        });
    }


}
